function fnCargarModulosUsuario(){

	var ruta = RUTA_CONTEXTO + "/ajax/cargar_modulosPanelPrincipal";
	$.ajax({
		url: ruta,
		type:'post',
		data:{},
		dataType:'json',
		success: function(data,textStatus,jqXHR){
			
			var statusText = textStatus;
	    	var responseText = data;
	    	
			if(statusText == 'success'){
				var jsonModulosArray = responseText;

				var i = 0;
				var htmlModulos = "";
				var dim = jsonModulosArray.length;
				
				while(i<dim){
					var objJSON = jsonModulosArray[i];

					var modulo = "<div class='moduloPanel'>"+
					"<a class='enlacePanel' href="+objJSON["rutaPagina"]+">"+
					"<img src='"+RUTA_CONTEXTO+"/"+objJSON["rutaImagen"]+"' />"+
					"<br class='clear' />"+objJSON["nombreModulo"]+"</a></div>";
					
					htmlModulos = htmlModulos + modulo;
					i = i + 1;
				}
				
				if(htmlModulos!=""){
					htmlModulos = htmlModulos +"<div class='clear'></div>";
					$("#panelControl").append(htmlModulos);
				}
	        }
		},
		error: function(jqXHR,textStatus,errorThrown) {
			var errorJquery = fnCapturarErrorJQueryAjax(jqXHR,textStatus);
			alert(errorJquery);
		}
	});
}

function fnCargarMenuUsuario(){
	
	var ruta = RUTA_CONTEXTO + "/ajax/cargar_menuUsuario";
	$.ajax({
		url: ruta,
		type:'post',
		data:{},
		dataType:'json',
		success: function(data,textStatus,jqXHR){
			
			var statusText = textStatus;
	    	var responseText = data;
	    	
			if(statusText == 'success'){
				var jsonMenuItemArray = responseText;

				var i = 0;
				var htmlMenu = "";
				var dim = jsonMenuItemArray.length;
				
				while(i<dim){
					var objJSON = jsonMenuItemArray[i];

					var item = "";
					if(objJSON["lstMenuItem"] == undefined){
						//Es un menu sin listado
						item = "<li class='ui-widget'><a class='fNiv' href='"+objJSON["url"]+"'>"+objJSON["label"]+"</a></li>";
					}else{
						//Construir submenus para cada elemento
						var subMenus = fnConstruirSubMenu(objJSON["lstMenuItem"]);
						item = "<li><a class='fNiv' href='"+objJSON["url"]+"'>"+objJSON["label"]+"</a>"+
							   		"<ul><li class='arrow'></li>"+subMenus+"</ul>"+
							   "</li>";
					}
					
					htmlMenu = htmlMenu + item;
					
					i = i + 1;
				}
				
				if(htmlMenu!=""){
					htmlMenu = "<ul id='listaMenu'>"+htmlMenu+"</ul>";
					$("#barraMenu").append(htmlMenu);
					$("#listaMenu").jMenu({
					      ulWidth : 'auto',
					      effects : {
					        effectSpeedOpen : 200,
					        TimeBeforeOpening : 200,
					        effectTypeOpen : 'fade',
					        effectSpeedClose:1
					      },
					      animatedText : false
					});
				}
	        }
		},
		error: function(jqXHR,textStatus,errorThrown) {
			var errorGrabacion = fnCapturarErrorJQueryAjax(jqXHR,textStatus);
			alert(errorGrabacion);
		}
	});
}

function fnConstruirSubMenu(lstMenuItem){
	var subMenu = "";
	
	if(lstMenuItem!=undefined){
		if(lstMenuItem.length > 0){
			var i = 0;
			var dim = lstMenuItem.length;

			while(i<dim){
				var objJSON = lstMenuItem[i];
				
				var item = "";
				if(objJSON["lstMenuItem"] == undefined){
					//Es un menu sin listado
					item = "<li class='ui-widget'><a href='"+objJSON["url"]+"'>"+objJSON["label"]+"</a></li>";
				}else{
					//Construir submenus para cada elemento
					var subMenus = fnConstruirSubMenu(objJSON["lstMenuItem"]);
					item = "<li class='ui-widget'><a href='"+objJSON["url"]+"'>"+objJSON["label"]+"</a>"+
						   		  "<ul>"+subMenus+"</ul>"+
						   	  "</li>";
				}
				
				subMenu = subMenu + item;
				
				i = i + 1;
			}
		}
	}
	
	return subMenu;

}

function fnCerrarSesion(){
	var sw = confirm("Desea cerrar la sesi\u00f3n ?");
	
	if(sw){
		location.href = RUTA_CONTEXTO+"/login/cerrarSesion";
	}
}